/**
 * 
 */
package recognition.preprocessor;

import utility.math.Vector2D;
import handwritten.gesture.Gesture;
import handwritten.gesture.MultiGesture;

/**
 * @author tioz
 *
 */
public class Smoother extends Preprocessor {

	/**
	 * implementation of the smoother of cellwritter
	 */
	public Smoother() {}

	/* (non-Javadoc)
	 * @see recognition.preprocessor.Preprocessor#preprocess(handwritten.gesture.MultiGesture)
	 */
	@Override
	protected boolean preprocess(MultiGesture gest) {
		
		Vector2D a,b,c,bma,cma;
		
		for(Gesture g : gest.getGesture())
		{
			for(int i=1;i<g.nPoint()-1;i++)
			{
				a = g.get(i-1);
				b = g.get(i  );
				c = g.get(i+1);
				
				bma = b.minus(a);
				cma = c.minus(a);
				
				b.set(a.plus(cma.time(bma.dotProduct(cma)/(2*cma.normSquared()))));
				
				
				//b.set(((a.plus(b)).time(1./2.)).(plus((c.minus(a)).time((b.minus(a)).dotProduct(c.minus(a))))).time(2*c.minus(a).normSquared())));
				//b.set(a.plus(b).time(1./2.));
				//b.set(new Vector2D(5,5));
				//System.out.println(b.getX());
				//System.out.println(b.getY());
				//System.out.println("C: " + c.display() + " A; "+a.display());
				//System.out.println(2*c.minus(a).normSquared());
			}
		}
		return true;
	}

}
